﻿@model IEnumerable<CubicFWNet.Data.SystemManage.Model.Module>
@{
    ViewBag.Title = "Index";
    var modules = ViewBag.Modules as IEnumerable<CubicFWNet.Data.SystemManage.Model.Module>;
}

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        系统菜单
    </h1>
    <ol class="breadcrumb">       
        <li><a href="@Url.Action("Index", "Home", new { area=""})">首页</a></li>
        <li class="active"><a href="@Url.Action("Index", "Module")">系统菜单</a></li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                    <button type="button" class="btn btn-primary" onclick="create();" title="新建"><i class="fa fa-plus-square"></i>&nbsp;新建</button>
                    <a class="btn btn-default" onclick="$.reload()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                </div>
                <div class="box-body" id="datatable">
                    @Html.Partial("_AjaxModuleTable", Model)
                </div>
            </div>

        </div>
    </div>
</section>
<!--编辑对话框-->
<div class="modal" id="editDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">添加/修改系统菜单</h4>
            </div>
            <form class="form-horizontal" id="frmedit" action="@Url.Action("Save","Module")">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> *@Html.DisplayNameFor(model => model.Name) </label>
                        <div class="col-sm-9">
                            <input type="hidden" class="form-control formId" id="Id" name="Id" />
                            <input type="text" class="form-control" id="Name" name="Name" required maxlength="50" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> @Html.DisplayNameFor(model => model.Url) </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Url" name="Url" maxlength="256" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> @Html.DisplayNameFor(model => model.IconName) </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="IconName" name="IconName" maxlength="256" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> @Html.DisplayNameFor(model => model.SortNo)  </label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="SortNo" name="SortNo" value="0" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> @Html.DisplayNameFor(model => model.IsLeaf) </label>
                        <label class="col-sm-9" style="padding-top:5px;">
                            <input type="checkbox" name="IsLeaf" id="IsLeaf">
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> @Html.DisplayNameFor(model => model.Status) </label>
                        <label class="col-sm-9" style="padding-top:5px;">
                            <input type="checkbox" name="Status" id="Status" checked>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> @Html.DisplayNameFor(model => model.ParentName)</label>
                        <div class="col-sm-9">
                            <input type="hidden" name="ParentName" id="ParentName" />
                            <select class="form-control" type="select" id="ParentId" name="ParentId">
                                <option value="">==请选择==</option>
                                @foreach (var module in modules)
                                {
                                    <option value="@module.Id.ToString()">@module.Name</option>
                                }
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">@Resources.Global.LoadingMsg</div>
</div>

@section Scripts {
    @{Html.RegisterMvcPagerScriptResource();}
    <script type="text/javascript">
        $(document).ready(function () {  
            $('#footable').footable({ "sort": false });

            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function (data) {
                            $.reload();
                        },
                        error: function (data) {
                            $.modalAlert(data.Message, data.Status);
                        }
                    });
                }
            });
            //$("#frmedit").html5Validate(function (form) {
            //    var postData = $(this).formSerialize();
            //    $.submitForm({
            //        url: $(this).attr("action"),
            //        param: postData,
            //        success: function () {
            //            $.reload();
            //        }
            //    });
            //});
            //iCheck for checkbox and radio inputs
            //$('input[type="checkbox"].flat-red').iCheck({
            //    checkboxClass: 'icheckbox_flat-green',
            //    radioClass: 'iradio_flat-green'
            //});
        });

        function create() {
            $("#frmedit").formInit("Id");
            $('#editDlg').modal();
        }

        function edit(id) {
            $.ajax({
                url: "/Module/GetFormJson",
                data: { id: id },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#frmedit").formSerialize(data);
                    $("#editDlg").modal();
                }
            });
        }

        function del(obj, id) {
            $.deleteForm({
                url: "/Module/Delete",
                param: { id: id },
                success: function () {
                    $(obj).parents("tr").remove();
                }
            });
        }        

    </script>
}
